<!-- create jishenghua-->
<template>
  <a-row :gutter="24">
    <a-col :md="24">
      <a-card :style="cardStyle" :bordered="false">
        <!-- 查询区域 -->
        <div class="table-page-search-wrapper">
          <!-- 搜索区域 -->
          <a-form layout="inline" @keyup.enter.native="searchQuery">
            <a-row :gutter="24">
              <a-col :md="6" :sm="24">
                <a-form-item label="内部编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入内部编码" v-model="queryParam.contractCode"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="客户名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-input placeholder="请输入客户名称" v-model="queryParam.customerName"></a-input>
                </a-form-item>
              </a-col>
              <a-col :md="6" :sm="24">
                <a-form-item label="计划发货时间" :labelCol="labelCol" :wrapperCol="wrapperCol">
                  <a-date-picker
                    style="width: 100%"
                    v-model="queryParam.createTime"
                    format="YYYY-MM-DD"
                    @change="formateDliveryDate"
                    placeholder="请输入计划发货时间"
                  />
                </a-form-item>
              </a-col>
              <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
                <a-col :md="6" :sm="24">
                  <a-button type="primary" @click="searchQuery">查询</a-button>
                  <a-button style="margin-left: 8px" @click="searchReset">重置</a-button>
                  <!-- <a @click="handleToggleSearch" style="margin-left: 8px">
                    {{ toggleSearchStatus ? '收起' : '展开' }}
                    <a-icon :type="toggleSearchStatus ? 'up' : 'down'" />
                  </a> -->
                </a-col>
              </span>
            </a-row>
          </a-form>
        </div>
        <!-- 操作按钮区域 -->
        <div class="table-operator" style="margin-top: 5px">
          <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
          <a-button @click="download()" type="primary" icon="download">导出</a-button>
        </div>
        <!-- table区域-begin -->
        <div>
          <a-table
            ref="table"
            size="middle"
            bordered
            rowKey="id"
            :columns="columns"
            :dataSource="dataSource"
            :pagination="ipagination"
            :scroll="scroll"
            :loading="loading"
            :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
            @change="handleTableChange"
          >
            <span slot="action" slot-scope="text, record">
              <a @click="HandleSee(record)">查看</a>
              <a-divider type="vertical" />
              <a @click="myHandleEdit(record)">编辑</a>
              <a-divider type="vertical" />
              <a-popconfirm title="确定删除吗?" @confirm="() => myHandleDelete(record)">
                <a>删除</a>
              </a-popconfirm>
            </span>
            <template slot="customRenderStatus" slot-scope="status">
              <a-tag v-if="status == '0'" color="red">未审核</a-tag>
              <a-tag v-if="status == '1'" color="green">已审核</a-tag>
              <a-tag v-if="status == '2'" color="cyan">完成销售</a-tag>
              <a-tag v-if="status == '3'" color="blue">部分销售</a-tag>
            </template>
          </a-table>
        </div>
        <!-- table区域-end -->
        <!-- 表单区域 -->
        <sale-order-modal ref="modalForm" @ok="modalFormOk"></sale-order-modal>
        <bill-detail ref="modalDetail"></bill-detail>
        <HandleSee ref="HandleSee" @ok="modalFormOk"></HandleSee>
      </a-card>
    </a-col>
  </a-row>
</template>
<script>
import SaleOrderModal from './dialog/SaleOrderModal'
import BillDetail from './dialog/BillDetail'
import HandleSee from './modules/HandleSee'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import { BillListMixin } from './mixins/BillListMixin'
import JDate from '@/components/jeecg/JDate'
import { downFile } from '@/api/manage'
import Vue from 'vue'
export default {
  name: 'SaleOrderList',
  mixins: [JeecgListMixin, BillListMixin],
  components: {
    SaleOrderModal,
    BillDetail,
    JDate,
    HandleSee
  },
  data() {
    return {
      // 查询条件
      queryParam: {
        number: '',
        materialParam: '',
        type: '其它',
        subType: '销售订单',
        roleType: Vue.ls.get('roleType'),
        organId: '',
        depotId: '',
        creator: ''
      },
      labelCol: {
        span: 5
      },
      wrapperCol: {
        span: 18,
        offset: 1
      },
      // 表头
      columns: [
        { title: '内部编码', dataIndex: 'contractCode', width: 145, align: 'center' },
        { title: '内部编码', dataIndex: 'contractCode', width: 145, align: 'center' },
        { title: '客户名称', dataIndex: 'customerName', width: 145, align: 'center' },
        { title: '计划发货时间', dataIndex: 'deliveryDate', width: 145, align: 'center' },
        { title: '发货时间预警', dataIndex: 'deliveryEarlyAlert', width: 145, align: 'center' },
        // { title: '生产任务单', dataIndex: 'productionTaskCode', width: 145 },
        // { title: '生产任务单文件', dataIndex: 'productionTaskUrl', width: 145 },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          width: 150,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/orderToProduction/page',
        exportXlsUrl: '/systemConfig/static/quotation',
        delete: '/orderToProduction/delete',
        deleteBatch: '/depotHead/deleteBatch',
        batchSetStatusUrl: '/depotHead/batchSetStatus'
      }
    }
  },
  created() {
    this.initCustomer()
    this.initUser()
  },
  computed: {},
  methods: {
    //导出
    download() {
      downFile('/orderToProduction/exportExcel').then(data => {
        if (!data) {
          this.$message.warning('文件下载失败')
          return
        }
        if (typeof window.navigator.msSaveBlob !== 'undefined') {
          window.navigator.msSaveBlob(new Blob([data], { type: 'application/vnd.ms-excel' }), '销售订单转换')
        } else {
          let url = window.URL.createObjectURL(new Blob([data], { type: 'application/vnd.ms-excel' }))
          let link = document.createElement('a')
          link.style.display = 'none'
          link.href = url
          link.setAttribute('download', '销售订单转换')
          document.body.appendChild(link)
          link.click()
          document.body.removeChild(link) //下载完成移除元素
          window.URL.revokeObjectURL(url) //释放掉blob对象
        }
      })
    },
    HandleSee(record) {
      this.$refs.HandleSee.edit(record)
      this.$refs.HandleSee.title = '查看'
      this.$refs.HandleSee.disableSubmit = false
    },
    formateDliveryDate: function(value, dateString) {
      this.queryParam.deliveryDate = dateString
      console.log(this.queryParam)
    },

    myHandleEdit(record) {
      this.$refs.modalForm.action = 'edit'
      this.handleEdit(record)
    },
    myHandleDelete(record) {
      this.handleDelete(record.id)
    }
  }
}
</script>
<style scoped>
/** Button按钮间距 */
.table-operator .ant-btn {
  margin: 0 8px 8px 0;
}
@import '~@assets/less/common.less';
</style>
